package cn.smile.controller.core;

import cn.smile.bean.dto.core.SysUserDTO;
import cn.smile.bean.form.core.user.*;
import cn.smile.bean.form.login.LoginInfoForm;
import cn.smile.business.core.ISysUserService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author smile-jt
 */
@RestController
@RequestMapping("api/user")
public class SysUserController {

    @Resource
    private ISysUserService service;

    @GetMapping("query/loginId")
    public MyResult<SysUserDTO> queryByLogin(@RequestParam("loginId") String loginId) {
        return MyResult.OK(service.queryByLogin(loginId));
    }

    @PostMapping("updateLoginTime")
    public MyResult<Boolean> updateLoginTime(@Valid @RequestBody LoginInfoForm form) {
        return MyResult.OK(service.updateLoginTime(form));
    }

    @PostMapping("query/page")
    public MyResult<IPage<SysUserDTO>> queryPage(@RequestBody QueryUserForm form) {
        return MyResult.OK(service.queryPage(form));
    }

    @PostMapping("query/list")
    public MyResult<List<SysUserDTO>> queryList(@RequestBody QueryUserForm form) {
        return MyResult.OK(service.queryList(form));
    }

    @PostMapping("registerUser")
    public MyResult<Boolean> registerUser(HttpServletRequest request, @Valid @RequestBody RegisterUserForm form) {
        return MyResult.OK(service.registerUser(request, form));
    }

    @GetMapping("checkLoginId")
    public MyResult<Boolean> checkLoginId(@RequestParam("loginId") String loginId) {
        return MyResult.OK(service.checkLoginId(loginId));
    }

    @GetMapping(value = "getUserInfo")
    public MyResult<SysUserDTO> getUserInfo() {
        return MyResult.OK(service.getUserInfo());
    }

    @PostMapping("changeAvatar")
    public MyResult<Boolean> changeAvatar(@Valid @RequestBody ChangeAvatarForm form){
        return MyResult.OK(service.changeAvatar(form));
    }

    @PostMapping(value = "updateLoginPwd")
    public MyResult<Boolean> updateLoginPwd(@Valid @RequestBody UpdatePwdForm form){
        return MyResult.OK(service.updateLoginPwd(form));
    }

    @PostMapping(value = "updateUserBase")
    public MyResult<Boolean> updateUserBase(@Valid @RequestBody UpdateUserBaseForm form){
        return MyResult.OK(service.updateUserBase(form));
    }
}
